package mia.recommender.ch02;

import org.apache.mahout.cf.taste.impl.model.file.*;
import org.apache.mahout.cf.taste.impl.model.jdbc.PostgreSQLJDBCDataModel;
import org.apache.mahout.cf.taste.impl.neighborhood.*;
import org.apache.mahout.cf.taste.impl.recommender.*;
import org.apache.mahout.cf.taste.impl.similarity.*;
import org.apache.mahout.cf.taste.model.*;
import org.apache.mahout.cf.taste.neighborhood.*;
import org.apache.mahout.cf.taste.recommender.*;
import org.apache.mahout.cf.taste.similarity.*;
import org.postgresql.ds.PGPoolingDataSource;
import java.util.*;

class RecommenderIntro {

  private RecommenderIntro() {
  }

  public static void main(String[] args) throws Exception {
	  
	  PGPoolingDataSource dataSource = new PGPoolingDataSource();
	  dataSource.setDataSourceName("DataSourcepostgres");
	  dataSource.setServerName("localhost");
	  dataSource.setDatabaseName("tesis");
	  dataSource.setUser("postgres");
	  dataSource.setPassword("P0stgressql");
	  dataSource.setMaxConnections(10);

	  
	  JDBCDataModel dataModel = new PostgreSQLJDBCDataModel(dataSource, "PUNTAJE", "USU_ID",
			  "PRO_ID", "PUN_VALOR", null);
			  

    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    UserNeighborhood neighborhood =
      new NearestNUserNeighborhood(2, similarity, dataModel);

    Recommender recommender = new GenericUserBasedRecommender(
    		dataModel, neighborhood, similarity);

    List<RecommendedItem> recommendations =
        recommender.recommend(1, 1);

    for (RecommendedItem recommendation : recommendations) {
      System.out.println(recommendation);
    }

  }

}
